#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int dst, int k) {
    const int INF = 0x3f3f3f3f;
    vector<vector<int>> f(n, vector<int>(k + 2, INF));
    f[src][0] = 0;
    for (int i = 1; i <= k + 1; i++)
        for (auto flight : flights)
        {
            int x = flight[0], y = flight[1], cost = flight[2];
            f[y][i] = min(f[y][i], f[x][i - 1] + cost);
        }

    int res = INF;
    for (int i = 1; i <= k + 1; i++)
        res = min(res, f[dst][i]);
    return (res == INF ? -1 : res);
}